#include	<stdint.h>
#include	<arpa/inet.h>

#include    "CommandFactory.h"
#include	"TestCommand.h"

/**
 * @brief  constructor for class CommandFactory
 */
//--------------------------------------------------------------------------------------
CommandFactory::CommandFactory () :
    _m_iOpenCount(0), _m_iCloseCount(0)
    { }

/**
 * @brief 
 * @return
 */
MyUtil::TaskPtr CommandFactory::create ( const MyUtil::PacketPtr &packet )
{
    if(packet->type() == CHANNEL_STATUS_CLOSE){
        this->_m_iCloseCount++;
        return NULL;
    }

    if(packet->type() == CHANNEL_STATUS_OPEN) {
        this->_m_iOpenCount++;
        return NULL;
    }
//#ifdef  USE_NET_BYTE
//    this->_m_iPacketLength = ntohl( *(int*)( packet->data.c_str() ) );
//    this->_m_iSummaryType = ntohl( *(int*)( packet->data.c_str() + 4 ) );
//    this->_m_iSubType = ntohl( *(int32_t*) (packet->data.c_str() + 8) );
//#else      // -----  not USE_NET_BYTE  -----
//    this->_m_iPacketLength = *(int*)( packet->data.c_str() );
//    this->_m_iSummaryType =  *(int*)( packet->data.c_str() + 4 );
//    this->_m_iSubType = ( *(int32_t*) (packet->data.c_str() + 8) );
//#endif     // -----  not USE_NET_BYTE  -----
//KittyLog::debug("packet length = %x, type = %x, %d", this->_m_iPacketLength, this->_m_iSummaryType, this->_m_iOpenCount );

    MyUtil::TaskPtr task = NULL;

    //switch ( this->_m_iSummaryType) {
    //    case 0x00000001:	
    //        task = new TestCommand( packet );
    //        break;
    //    default:	
    //        break;
    //}				// -----  end switch  -----
    task = new TestCommand( packet );
    return task;
}		
